package cn.kgc.faqs.service;

import cn.kgc.faqs.mapper.ClassMapper;
import cn.kgc.faqs.mapper.FaqsMapper;
import cn.kgc.faqs.pojo.Class;
import cn.kgc.faqs.pojo.Faqs;
import cn.kgc.faqs.pojo.FaqsExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ClassServiceImpl implements  ClassService {

    @Resource
    FaqsMapper faqsMapper;
    @Resource
    ClassMapper classMapper;

    @Override
    public List<Faqs> selectAllFaqs(String title) {
        List<Faqs> faqsList =new ArrayList<>();
        if (title!=null){
            FaqsExample example=new FaqsExample();
            FaqsExample.Criteria criteria=example.createCriteria();
            criteria.andTitleLike("%"+title+"%");
            faqsList=faqsMapper.selectByExample(example);
        }else{
            faqsList=faqsMapper.selectByExample(null);
        }
        return faqsList;
    }

    @Override
    public List<Class> selectAllClass() {
        List<Class> classList = classMapper.selectByExample(null);
        return classList;
    }

    @Override
    public Integer saveFaqs(Faqs faqs) {
        return faqsMapper.insertSelective(faqs);
    }

    @Override
    public Faqs selectAllById(Integer id) {
        Faqs faqs = faqsMapper.selectByPrimaryKey(id);
        return faqs;
    }
}
